package com.youhui.weixin.utils;

import com.youhui.weixin.common.exception.LoadFileException;
import com.youhui.weixin.common.info.MythExceptionList;

import java.io.InputStream;
import java.util.Properties;

/**
 * Created by https://github.com/kuangcp on 17-10-6  下午3:12
 * 处理properties文件的工具类
 */
public class PropertiesLoad {
    /**
     * 采用Maven或者gradle构建时resources下的文件直接写文件名即可
     * @param filePath 文件路径
     * @return 文件对象
     * @throws LoadFileException 文件路径错误
     */
    public static  Properties loadConfig(String filePath) throws LoadFileException {
        InputStream in = PropertiesLoad.class.getClassLoader().getResourceAsStream(filePath);
        Properties properties = new Properties();
        try {
            properties.load(in);
        } catch (Exception e) {
            throw new LoadFileException(MythExceptionList.LOAD_FILE_EXCEPTION,e,PropertiesLoad.class);
        }
        return properties;
    }
}
